package Dao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import Entity.Transfer;

public class MakeNewDaoHelper {
	public void makeNewTransfer(Transfer transfer) throws SQLException,ClassNotFoundException,IOException{
		Connection con = DaoUtil.getConnection();
		String sql = "INSERT INTO Transfer(EmpNumber,EmpName,FromLocation,ToLocation,FromProject,ToProject,FromDept,ToDept,RelievingDate,JoiningDate,Approval) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
		stm.setString(1, transfer.getEmpNumber());
		stm.setString(2, transfer.getEmpName());
		stm.setString(3, transfer.getFromLocation());
		stm.setString(4, transfer.getToLocation());
		stm.setString(5, transfer.getFromProject());
		stm.setString(6, transfer.getToProject());
		stm.setString(7, transfer.getFromDepartment());
		stm.setString(8, transfer.getToDepartment());		
		stm.setString(9, transfer.getRelieveDate());
		stm.setString(10,transfer.getJoinDate());	
		stm.setString(11, "Yes");
		stm.execute();
		DaoUtil.closeConnection(con);
	}
	public List<String> loadLocation() throws SQLException,ClassNotFoundException,IOException{
		String sql = "select * from Location";
		Connection con = DaoUtil.getConnection();
		List<String> StringList = new Vector<String>();
		PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
		ResultSet rs = stm.executeQuery();
		while (rs.next()){
			StringList.add(rs.getString("Names"));
		}
		DaoUtil.closeConnection(con);
		return StringList;
		
	}
	
	public List<String> loadProject() throws SQLException,ClassNotFoundException,IOException{
		String sql = "select * from Project";
		Connection con = DaoUtil.getConnection();
		List<String> StringList = new Vector<String>();
		PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
		ResultSet rs = stm.executeQuery();
		while (rs.next()){
			StringList.add(rs.getString("Names"));
		}
		DaoUtil.closeConnection(con);
		return StringList;
	}
	
	public List<String> loadDepartment() throws SQLException,ClassNotFoundException,IOException{
		String sql = "select * from Department";
		Connection con = DaoUtil.getConnection();
		List<String> StringList = new Vector<String>();
		PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
		ResultSet rs = stm.executeQuery();
		while (rs.next()){
			StringList.add(rs.getString("Names"));
		}
		DaoUtil.closeConnection(con);
		return StringList;
	}
	
	public List<String> loadNumber() throws SQLException,ClassNotFoundException,IOException{
		String sql = "select * from Employee";
		Connection con = DaoUtil.getConnection();
		List<String> StringList = new Vector<String>();
		PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
		ResultSet rs = stm.executeQuery();
		while (rs.next()){
			StringList.add(rs.getString("EmpNumber"));
		}
		DaoUtil.closeConnection(con);
		return StringList;
	}
	
	public List<String> loadName() throws SQLException,ClassNotFoundException,IOException{
		String sql = "select * from Employee";
		Connection con = DaoUtil.getConnection();
		List<String> StringList = new Vector<String>();
		PreparedStatement stm = DaoUtil.getPreparedStatement(con, sql);
		ResultSet rs = stm.executeQuery();
		while (rs.next()){
			StringList.add(rs.getString("EmpName"));
		}
		DaoUtil.closeConnection(con);
		return StringList;
	}
}
